package com.ruoyi.project.report.stats.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.report.stats.domain.IpStats;
import com.ruoyi.project.report.stats.service.IIpStatsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * IP统计Controller
 * 
 * @author shixiangwen
 * @date 2020-01-09
 */
@Controller
@RequestMapping("/report/stats")
public class IpStatsController extends BaseController {
	private String prefix = "report/stats";

	@Autowired
	private IIpStatsService ipStatsService;

	@RequiresPermissions("report:stats:view")
	@GetMapping()
	public String stats() {
		return prefix + "/stats";
	}

	/**
	 * 查询IP统计列表
	 */
	@RequiresPermissions("report:stats:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IpStats ipStats) {
		startPage();
		List<IpStats> list = ipStatsService.selectIpStatsList(ipStats);
		return getDataTable(list);
	}

	/**
	 * 导出IP统计列表
	 */
	@RequiresPermissions("report:stats:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(IpStats ipStats) {
		List<IpStats> list = ipStatsService.selectIpStatsList(ipStats);
		ExcelUtil<IpStats> util = new ExcelUtil<IpStats>(IpStats.class);
		return util.exportExcel(list, "stats");
	}

	/**
	 * 新增IP统计
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存IP统计
	 */
	@RequiresPermissions("report:stats:add")
	@Log(title = "IP统计", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IpStats ipStats) {
		return toAjax(ipStatsService.insertIpStats(ipStats));
	}

	/**
	 * 修改IP统计
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		IpStats ipStats = ipStatsService.selectIpStatsById(id);
		mmap.put("ipStats", ipStats);
		return prefix + "/edit";
	}

	/**
	 * 修改保存IP统计
	 */
	@RequiresPermissions("report:stats:edit")
	@Log(title = "IP统计", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IpStats ipStats) {
		return toAjax(ipStatsService.updateIpStats(ipStats));
	}

	/**
	 * 删除IP统计
	 */
	@RequiresPermissions("report:stats:remove")
	@Log(title = "IP统计", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(ipStatsService.deleteIpStatsByIds(ids));
	}
}
